package com.cloud.uid.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.cloud.uid.service.UidGenService;
import org.jasypt.encryption.StringEncryptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UidController {

    @Autowired
    private UidGenService uidGenService;

    @Autowired
    private StringEncryptor stringEncryptor;

    @GetMapping("/getUid")
    public String UidGenerator() {

        JSONObject jsonObject = JSON.parseObject(uidGenService.getUid());
        return jsonObject.get("UID").toString();
    }

    /**
     * 加密方法 ，传入加密参数
     * @param text
     * @return
     */
    @GetMapping("/encode")
    public String UidGenerator(String text) {

        return stringEncryptor.encrypt(text);
    }


}
